package com.zhang;

import com.zhang.constant.Constant;
import com.zhang.core.Downloader;
import com.zhang.util.HttpUtils;
import com.zhang.util.LogUtils;

import java.io.IOException;
import java.util.Scanner;

public class Main {

    // https://dldir1.qq.com/qqfile/qq/PCQQ9.7.1/QQ9.7.1.28940.exe


    public static void main(String[] args) {
        String url = null;
        if (args == null || args.length == 0) {
            for (; ; ) {
                Scanner scanner = new Scanner(System.in);
                System.out.println("请输入下载地址：");
                url = scanner.next();
                if (url != null) {
                    break;
                }
            }
        }else {
            url = args[0];
        }

        //doDownload
        Downloader downloader = new Downloader();
        try {
            downloader.download(url);
        } catch (IOException e) {
            LogUtils.error("下载出错" + e.getStackTrace());
            return;
        }
        System.out.println("任务完毕！" + (Constant.PATH + HttpUtils.getHttpFileName(url)));
    }
}
